home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SRCBDTO.PAK / FIELD.CPP < prev    next >
Text File  |  1997-05-06  |  27KB  |  1,088 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // field.cpp
  6. // TField and TBlobField wrapper classes
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdto.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. #include "wrapit.h"
  14. #include "misc.h"
  15.  
  16. //-----------------------------------------------------------------------------
  17.  
  18. static void _export STDAPICALLTYPE FieldNotifyEventCallback( int32 data, PITField field )
  19. {
  20.     if (data)
  21.     {
  22.         PTField ezField = WrapPITField( field );
  23.  
  24.         TFieldNotifySource* source = (TFieldNotifySource*) data;
  25.         (*source)( *ezField );
  26.  
  27.         if (ezField)
  28.             delete ezField;
  29.     }
  30. }
  31.  
  32. void TField::AttachOnChange( const TBdtEventSourceBase&, bool attach )
  33. {
  34.     if (field)
  35.     {
  36.         AttachedOnChange = attach;
  37.         if (attach)
  38.             field->AttachOnChange( FieldNotifyEventCallback, (int32) &OnChangeSource );
  39.         else
  40.             field->DetachOnChange( FieldNotifyEventCallback, (int32) &OnChangeSource );
  41.     }
  42. }
  43.  
  44. void TField::AttachOnValidate( const TBdtEventSourceBase&, bool attach )
  45. {
  46.     if (field)
  47.     {
  48.         AttachedOnValidate = attach;
  49.         if (attach)
  50.             field->AttachOnValidate( FieldNotifyEventCallback, (int32) &OnValidateSource );
  51.         else
  52.             field->DetachOnValidate( FieldNotifyEventCallback, (int32) &OnValidateSource );
  53.     }
  54. }
  55.  
  56.  
  57. static void _export STDAPICALLTYPE FieldGetTextEventCallback( int32 data, PITField field, PITAnyString Text, VARIANT_BOOL DisplayText )
  58. {
  59.     if (data)
  60.     {
  61.         PTField ezField = WrapPITField( field );
  62.         string* ezText = new string;
  63.         AnyString( Text ).GetString( *ezText );
  64.         bool ezDisplayText = MakeBool( DisplayText );
  65.  
  66.         TFieldGetTextSource* source = (TFieldGetTextSource*) data;
  67.         (*source)( *ezField, *ezText, ezDisplayText );
  68.  
  69.         if (ezText)
  70.         {
  71.             Text->put_AsStringBuf( ezText->c_str() );
  72.             delete ezText;
  73.         }
  74.         if (ezField)
  75.             delete ezField;
  76.     }
  77. }
  78.  
  79. void TField::AttachOnGetText( const TBdtEventSourceBase&, bool attach )
  80. {
  81.     if (field)
  82.     {
  83.         AttachedOnGetText = attach;
  84.         if (attach)
  85.             field->AttachOnGetText( FieldGetTextEventCallback, (int32) &OnGetTextSource );
  86.         else
  87.             field->DetachOnGetText( FieldGetTextEventCallback, (int32) &OnGetTextSource );
  88.     }
  89. }
  90.  
  91. static void _export STDAPICALLTYPE FieldSetTextEventCallback( int32 data, PITField field, PITAnyString Text )
  92. {
  93.     if (data)
  94.     {
  95.         PTField ezField = WrapPITField( field );
  96.         string* ezText = new string;
  97.         AnyString( Text ).GetString( *ezText );
  98.  
  99.         TFieldSetTextSource* source = (TFieldSetTextSource*) data;
  100.         (*source)( *ezField, *ezText );
  101.  
  102.         if (ezText)
  103.             delete ezText;
  104.         if (ezField)
  105.             delete ezField;
  106.     }
  107. }
  108.  
  109. void TField::AttachOnSetText( const TBdtEventSourceBase&, bool attach )
  110. {
  111.     if (field)
  112.     {
  113.         AttachedOnSetText = attach;
  114.         if (attach)
  115.             field->AttachOnSetText( FieldSetTextEventCallback, (int32) &OnSetTextSource );
  116.         else
  117.             field->DetachOnSetText( FieldSetTextEventCallback, (int32) &OnSetTextSource );
  118.     }
  119. }
  120.  
  121. void TField::DetachEvents( void )
  122. {
  123.     if (field)
  124.     {
  125.         if (AttachedOnChange)
  126.             field->DetachOnChange( FieldNotifyEventCallback, (int32) &OnChangeSource );
  127.         if (AttachedOnGetText)
  128.             field->DetachOnGetText( FieldGetTextEventCallback, (int32) &OnGetTextSource );
  129.         if (AttachedOnSetText)
  130.             field->DetachOnSetText( FieldSetTextEventCallback, (int32) &OnSetTextSource );
  131.         if (AttachedOnValidate)
  132.             field->DetachOnValidate( FieldNotifyEventCallback, (int32) &OnValidateSource );
  133.     }
  134. }
  135.  
  136. void TField::ReattachEvents( void )
  137. {
  138.     if (field)
  139.     {
  140.         if (AttachedOnChange)
  141.             field->AttachOnChange( FieldNotifyEventCallback, (int32) &OnChangeSource );
  142.         if (AttachedOnGetText)
  143.             field->AttachOnGetText( FieldGetTextEventCallback, (int32) &OnGetTextSource );
  144.         if (AttachedOnSetText)
  145.             field->AttachOnSetText( FieldSetTextEventCallback, (int32) &OnSetTextSource );
  146.         if (AttachedOnValidate)
  147.             field->AttachOnValidate( FieldNotifyEventCallback, (int32) &OnValidateSource );
  148.     }
  149. }
  150.  
  151. //-----------------------------------------------------------------------------
  152.  
  153. void TField::SetTField( PIUnknown p )
  154. {
  155.     field = 0;
  156.     if (p)
  157.         p->QueryInterface( IID_ITField, (void**) &field );
  158.     ReattachEvents();
  159. }
  160.  
  161. void TField::ClearTField( void )
  162. {
  163.     DetachEvents();
  164.     if (field)
  165.     {
  166.         field->Release();
  167.         field = 0;
  168.     }
  169. }
  170.  
  171. TField::TField( PTBDTComponent Owner, TFieldType DataType ) :
  172.     TBDTComponent(),
  173.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnChange ) ),
  174.     AttachedOnChange( false ),
  175.     OnGetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnGetText ) ),
  176.     AttachedOnGetText( false ),
  177.     OnSetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnSetText ) ),
  178.     AttachedOnSetText( false ),
  179.     OnValidateSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnValidate ) ),
  180.     AttachedOnValidate( false )
  181. {
  182.     field = CreateITField( Owner ? Owner->GetPITBDTComponent() : 0, DataType);
  183.     TBDTComponent::SetPIT( field );
  184. }
  185.  
  186. TField::TField( void ) :
  187.     TBDTComponent(),
  188.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnChange ) ),
  189.     AttachedOnChange( false ),
  190.     OnGetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnGetText ) ),
  191.     AttachedOnGetText( false ),
  192.     OnSetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnSetText ) ),
  193.     AttachedOnSetText( false ),
  194.     OnValidateSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnValidate ) ),
  195.     AttachedOnValidate( false )
  196. {
  197.     field = CreateITField( 0, ftUnknown);
  198.     TBDTComponent::SetPIT( field );
  199. }
  200.  
  201. TField::TField( PITField p ) :
  202.     TBDTComponent( p ),
  203.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnChange ) ),
  204.     AttachedOnChange( false ),
  205.     OnGetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnGetText ) ),
  206.     AttachedOnGetText( false ),
  207.     OnSetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnSetText ) ),
  208.     AttachedOnSetText( false ),
  209.     OnValidateSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnValidate ) ),
  210.     AttachedOnValidate( false )
  211. {
  212.     SetTField( p );
  213. }
  214.  
  215. TField::TField( const TField& p ) :
  216.     TBDTComponent( p ),
  217.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnChange ) ),
  218.     AttachedOnChange( false ),
  219.     OnGetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnGetText ) ),
  220.     AttachedOnGetText( false ),
  221.     OnSetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnSetText ) ),
  222.     AttachedOnSetText( false ),
  223.     OnValidateSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnValidate ) ),
  224.     AttachedOnValidate( false )
  225. {
  226.     SetTField( p.field );
  227. }
  228.  
  229. TField::TField( PTField p ) :
  230.     TBDTComponent( p ),
  231.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnChange ) ),
  232.     AttachedOnChange( false ),
  233.     OnGetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnGetText ) ),
  234.     AttachedOnGetText( false ),
  235.     OnSetTextSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnSetText ) ),
  236.     AttachedOnSetText( false ),
  237.     OnValidateSource( SrcAttach_MFUNCTOR( *this, &TField::AttachOnValidate ) ),
  238.     AttachedOnValidate( false )
  239. {
  240.     SetTField( p ? p->field : 0 );
  241. }
  242.  
  243. TField& TField::operator=( PITField p )
  244. {
  245.     TBDTComponent::operator=(p);
  246.     ClearTField();
  247.     SetTField( p );
  248.     return *this;
  249. }
  250.  
  251. TField& TField::operator=( const TField& p )
  252. {
  253.     if (this != &p)
  254.     {
  255.         TBDTComponent::operator=(p);
  256.         ClearTField();
  257.         SetTField( p.field );
  258.     }
  259.     return *this;
  260. }
  261.  
  262. int TField::operator==( const TField& p ) const
  263. {
  264.     if (this == &p)
  265.         return true;
  266.     if (field == p.field)
  267.         return true;
  268.     return false;
  269. }
  270.  
  271. int TField::operator!=( const TField& p ) const
  272. {
  273.     return ! operator==(p);
  274. }
  275.  
  276. TField::~TField()
  277. {
  278.     ClearTField();
  279. }
  280.  
  281. void TField::SetPIT( PIUnknown p )
  282. {
  283.     ClearTField();
  284.     SetTField( p );
  285.     TBDTComponent::SetPIT( p );
  286. }
  287.  
  288. void TField::AssignValue( TVarRec& v )
  289. {
  290.     if (field)
  291.         field->AssignValue( v.GetVariant() );
  292. }
  293.  
  294. void TField::Clear( void )
  295. {
  296.     if (field)
  297.         field->Clear();
  298. }
  299.  
  300. bool TField::GetData( LPVOID buffer )
  301. {
  302.     if (field)
  303.         return MakeBool( field->GetData( buffer ) );
  304.     return true;
  305. }
  306.  
  307. void TField::SetData( LPVOID buffer )
  308. {
  309.     if (field)
  310.         field->SetData( buffer );
  311. }
  312.  
  313. bool TField::IsValidChar( char c )
  314. {
  315.     if (field)
  316.         return MakeBool( field->IsValidChar( c ) );
  317.     return false;
  318. }
  319.  
  320. DEFINE_BDTO_PROP_RW( TField, bool, AsBoolean );
  321. DEFINE_BDTO_PROP_RW( TField, DATE, AsDateTime );
  322. DEFINE_BDTO_PROP_RW( TField, double, AsFloat );
  323. DEFINE_BDTO_PROP_RW( TField, int32, AsInteger );
  324. DEFINE_BDTO_OBJECTPROP_RW( TField, string, AsString );
  325. DEFINE_BDTO_PROP_RO( TField, bool, CanModify );
  326. DEFINE_BDTO_OBJECTPROP_RW_FAST( TField, TDataSet, PITDataSet, DataSet );
  327. DEFINE_BDTO_PROP_RO( TField, int, DataSize );
  328. DEFINE_BDTO_PROP_RO( TField, TFieldType, DataType );
  329. DEFINE_BDTO_OBJECTPROP_RO( TField, string, DisplayText );
  330. DEFINE_BDTO_OBJECTPROP_RW( TField, string, EditMask );
  331. DEFINE_BDTO_PROP_RO( TField, int, FieldNo );
  332. DEFINE_BDTO_PROP_RO( TField, bool, IsIndexField );
  333. DEFINE_BDTO_PROP_RO( TField, bool, IsNull );
  334. DEFINE_BDTO_PROP_RW( TField, uint16, Size );
  335. DEFINE_BDTO_OBJECTPROP_RW( TField, string, Text );
  336.  
  337. void TField::GetAsBoolean( bool& b )
  338. {
  339.     if (field)
  340.         b = MakeBool( field->get_AsBoolean() );
  341. }
  342.  
  343. void TField::SetAsBoolean( bool b )
  344. {
  345.     if (field)
  346.         field->put_AsBoolean( MakeVariantBool( b ) );
  347. }
  348.  
  349. void TField::GetAsDateTime( DATE& d )
  350. {
  351.     if (field)
  352.         d = field->get_AsDateTime();
  353. }
  354.  
  355. void TField::SetAsDateTime( DATE d )
  356. {
  357.     if (field)
  358.         field->put_AsDateTime( d );
  359. }
  360.  
  361. void TField::GetAsFloat( double& d )
  362. {
  363.     if (field)
  364.         d = field->get_AsFloat();
  365. }
  366.  
  367. void TField::SetAsFloat( double d )
  368. {
  369.     if (field)
  370.         field->put_AsFloat( d );
  371. }
  372.  
  373. void TField::GetAsInteger( int32& i )
  374. {
  375.     if (field)
  376.         i = field->get_AsInteger();
  377. }
  378.  
  379. void TField::SetAsInteger( int32 i )
  380. {
  381.     if (field)
  382.         field->put_AsInteger( i );
  383. }
  384.  
  385. void TField::GetAsString( string& s )
  386. {
  387.     if (field)
  388.         AnyString( field->get_AsString() ).GetString( s );
  389. }
  390.  
  391. void TField::SetAsString( const string& s )
  392. {
  393.     if (field)
  394.         field->put_AsString( AnyString(s).GetPITAnyString() );
  395. }
  396.  
  397. void TField::GetCanModify( bool& c )
  398. {
  399.     if (field)
  400.         c = MakeBool( field->get_CanModify() );
  401. }
  402.  
  403. void TField::GetDataSet( TDataSet& d )
  404. {
  405.     if (field)
  406.     {
  407.         PITDataSet pit = field->get_DataSet();
  408.         if (pit)
  409.         {
  410.             d.SetPIT( pit );
  411.             pit->Release();
  412.         }
  413.     }
  414. }
  415.  
  416. void TField::SetDataSet( const TDataSet& d )
  417. {
  418.     if (field)
  419.         field->put_DataSet( d.GetPITDataSet() );
  420. }
  421.  
  422. void TField::GetDataSize( int& s )
  423. {
  424.     if (field)
  425.         s = field->get_DataSize();
  426. }
  427.  
  428. void TField::GetDataType( TFieldType& t )
  429. {
  430.     if (field)
  431.         t = field->get_DataType();
  432. }
  433.  
  434. void TField::GetDisplayText( string& s )
  435. {
  436.     if (field)
  437.         AnyString( field->get_DisplayText() ).GetString( s );
  438. }
  439.  
  440. void TField::GetEditMask( string& s )
  441. {
  442.     if (field)
  443.         AnyString( field->get_EditMask() ).GetString( s );
  444. }
  445.  
  446. void TField::SetEditMask( const string& m )
  447. {
  448.     if (field)
  449.         field->put_EditMask( AnyString(m).GetPITAnyString() );
  450. }
  451.  
  452. void TField::GetFieldNo( int& n )
  453. {
  454.     if (field)
  455.         n = field->get_FieldNo();
  456. }
  457.  
  458. void TField::GetIsIndexField( bool& i )
  459. {
  460.     if (field)
  461.         i = MakeBool( field->get_IsIndexField() );
  462. }
  463.  
  464. void TField::GetIsNull( bool& i )
  465. {
  466.     if (field)
  467.         i = MakeBool( field->get_IsNull() );
  468. }
  469.  
  470. void TField::GetSize( uint16& s )
  471. {
  472.     if (field)
  473.         s = field->get_Size();
  474. }
  475.  
  476. void TField::SetSize( uint16 s )
  477. {
  478.     if (field)
  479.         field->put_Size( s );
  480. }
  481.  
  482. void TField::GetText( string& s )
  483. {
  484.     if (field)
  485.         AnyString( field->get_Text() ).GetString( s );
  486. }
  487.  
  488. void TField::SetText( const string& t )
  489. {
  490.     if (field)
  491.         field->put_Text( AnyString(t).GetPITAnyString() );
  492. }
  493.  
  494. DEFINE_BDTO_PROP_RW( TField, bool, Calculated );
  495. DEFINE_BDTO_OBJECTPROP_RW( TField, string, FieldName );
  496. DEFINE_BDTO_PROP_RW( TField, int, Index );
  497. DEFINE_BDTO_PROP_RW( TField, bool, ReadOnly );
  498. DEFINE_BDTO_PROP_RW( TField, bool, Required );
  499. DEFINE_BDTO_PROP_RW( TField, bool, Visible );
  500.  
  501. void TField::GetCalculated( bool& c )
  502. {
  503.     if (field)
  504.         c = MakeBool( field->get_Calculated() );
  505. }
  506.  
  507. void TField::SetCalculated( bool c )
  508. {
  509.     if (field)
  510.         field->put_Calculated( MakeVariantBool( c ) );
  511. }
  512.  
  513. void TField::GetFieldName( string& s )
  514. {
  515.     if (field)
  516.         AnyString( field->get_FieldName() ).GetString( s );
  517. }
  518.  
  519. void TField::SetFieldName( const string& n )
  520. {
  521.     if (field)
  522.         field->put_FieldName( AnyString(n).GetPITAnyString() );
  523. }
  524.  
  525. void TField::GetIndex( int& i )
  526. {
  527.     if (field)
  528.         i = field->get_Index();
  529. }
  530.  
  531. void TField::SetIndex( int i )
  532. {
  533.     if (field)
  534.         field->put_Index( i );
  535. }
  536.  
  537. void TField::GetReadOnly( bool& r )
  538. {
  539.     if (field)
  540.         r = MakeBool( field->get_ReadOnly() );
  541. }
  542.  
  543. void TField::SetReadOnly( bool r )
  544. {
  545.     if (field)
  546.         field->put_ReadOnly( MakeVariantBool( r ) );
  547. }
  548.  
  549. void TField::GetRequired( bool& r )
  550. {
  551.     if (field)
  552.         r = MakeBool( field->get_Required() );
  553. }
  554.  
  555. void TField::SetRequired( bool r )
  556. {
  557.     if (field)
  558.         field->put_Required( MakeVariantBool( r ) );
  559. }
  560.  
  561. void TField::SetVisible( bool v )
  562. {
  563.     if (field)
  564.         field->put_Visible( MakeVariantBool( v ) );
  565. }
  566.  
  567. void TField::GetVisible( bool& v )
  568. {
  569.     if (field)
  570.         v = MakeBool( field->get_Visible() );
  571. }
  572.  
  573. //-----------------------------------------------------------------------------
  574.  
  575. #define DEFINE_DERIVED_FIELD( type, base )                                    \
  576.     type::type( PITField p ) : base( p )                                       \
  577.     {                                                                          \
  578.     }                                                                          \
  579.     type::type( const TField& p ) : base( p )                                  \
  580.     {                                                                          \
  581.     }                                                                          \
  582.     type::type( PTField p ) : base( p )                                        \
  583.     {                                                                          \
  584.     }                                                                          \
  585.     type& type::operator=( PITField p )                                        \
  586.     {                                                                          \
  587.         base::operator=(p);                                                     \
  588.         return *this;                                                           \
  589.     }                                                                          \
  590.     type& type::operator=( const TField& p )                                   \
  591.     {                                                                          \
  592.         if (this != &p)                                                         \
  593.             base::operator=(p);                                                  \
  594.         return *this;                                                           \
  595.     }                                                                          \
  596.     int type::operator==( const TField& p ) const                              \
  597.     {                                                                          \
  598.         return base::operator==(p);                                             \
  599.     }                                                                          \
  600.     int type::operator!=( const TField& p ) const                              \
  601.     {                                                                          \
  602.         return base::operator!=(p);                                             \
  603.     }                                                                          \
  604.     type::~type()                                                              \
  605.     {                                                                          \
  606.     }
  607.  
  608. //-----------------------------------------------------------------------------
  609.  
  610. DEFINE_DERIVED_FIELD( TStringField, TField )
  611.  
  612. TStringField::TStringField( void ) : TField( 0, ftString )
  613. {
  614. }
  615.  
  616. TStringField::TStringField( PTBDTComponent Owner ) : TField( Owner, ftString )
  617. {
  618. }
  619.  
  620. DEFINE_BDTO_OBJECTPROP_RW( TStringField, string, Value );
  621.  
  622. void TStringField::GetValue( string& s )
  623. {
  624.     GetAsString( s );
  625. }
  626.  
  627. void TStringField::SetValue( const string& s )
  628. {
  629.     SetAsString( s );
  630. }
  631.  
  632. DEFINE_BDTO_PROP_RW( TStringField, bool, Transliterate );
  633.  
  634. void TStringField::GetTransliterate( bool& t )
  635. {
  636.     if (field)
  637.         t = MakeBool( field->get_Transliterate() );
  638. }
  639.  
  640. void TStringField::SetTransliterate( bool t )
  641. {
  642.     if (field)
  643.         field->put_Transliterate( MakeVariantBool( t ) );
  644. }
  645.  
  646. //-----------------------------------------------------------------------------
  647.  
  648. DEFINE_DERIVED_FIELD( TNumericField, TField )
  649.  
  650. TNumericField::TNumericField( void ) : TField( 0, ftFloat )
  651. {
  652. }
  653.  
  654. TNumericField::TNumericField( PTBDTComponent Owner, TFieldType DataType ) : TField( Owner, DataType )
  655. {
  656. }
  657.  
  658. DEFINE_BDTO_OBJECTPROP_RW( TNumericField, string, DisplayFormat );
  659. DEFINE_BDTO_OBJECTPROP_RW( TNumericField, string, EditFormat );
  660.  
  661. void TNumericField::GetDisplayFormat( string& s )
  662. {
  663.     if (field)
  664.         AnyString( field->get_DisplayFormat() ).GetString( s );
  665. }
  666.  
  667. void TNumericField::SetDisplayFormat( const string& s )
  668. {
  669.     if (field)
  670.         field->put_DisplayFormat( AnyString(s).GetPITAnyString() );
  671. }
  672.  
  673. void TNumericField::GetEditFormat( string& s )
  674. {
  675.     if (field)
  676.         AnyString( field->get_EditFormat() ).GetString( s );
  677. }
  678.  
  679. void TNumericField::SetEditFormat( const string& s )
  680. {
  681.     if (field)
  682.         field->put_EditFormat( AnyString(s).GetPITAnyString() );
  683. }
  684.  
  685. //-----------------------------------------------------------------------------
  686.  
  687. DEFINE_DERIVED_FIELD( TIntegerField, TNumericField )
  688.  
  689. TIntegerField::TIntegerField( void ) : TNumericField( 0, ftInteger )
  690. {
  691. }
  692.  
  693. TIntegerField::TIntegerField( PTBDTComponent Owner ) : TNumericField( Owner, ftInteger )
  694. {
  695. }
  696.  
  697. TIntegerField::TIntegerField( PTBDTComponent Owner, TFieldType DataType ) : TNumericField( Owner, DataType )
  698. {
  699. }
  700.  
  701. DEFINE_BDTO_PROP_RW( TIntegerField, int32, Value );
  702.  
  703. void TIntegerField::GetValue( int32& v )
  704. {
  705.     GetAsInteger( v );
  706. }
  707.  
  708. void TIntegerField::SetValue( int32 v )
  709. {
  710.     SetAsInteger( v );
  711. }
  712.  
  713. DEFINE_BDTO_PROP_RW( TIntegerField, int32, MaxValue );
  714. DEFINE_BDTO_PROP_RW( TIntegerField, int32, MinValue );
  715.  
  716. void TIntegerField::GetMaxValue( int32& v )
  717. {
  718.     if (field)
  719.         v = field->get_MaxValueAsInteger();
  720. }
  721.  
  722. void TIntegerField::SetMaxValue( int32 v )
  723. {
  724.     if (field)
  725.         field->put_MaxValueAsInteger( v );
  726. }
  727.  
  728. void TIntegerField::GetMinValue( int32& v )
  729. {
  730.     if (field)
  731.         v = field->get_MinValueAsInteger();
  732. }
  733.  
  734. void TIntegerField::SetMinValue( int32 v )
  735. {
  736.     if (field)
  737.         field->put_MinValueAsInteger( v );
  738. }
  739.  
  740. //-----------------------------------------------------------------------------
  741.  
  742. DEFINE_DERIVED_FIELD( TSmallintField, TIntegerField )
  743.  
  744. TSmallintField::TSmallintField( void ) : TIntegerField( 0, ftSmallint )
  745. {
  746. }
  747.  
  748. TSmallintField::TSmallintField( PTBDTComponent Owner ) : TIntegerField( Owner, ftSmallint )
  749. {
  750. }
  751.  
  752. //-----------------------------------------------------------------------------
  753.  
  754. DEFINE_DERIVED_FIELD( TWordField, TIntegerField )
  755.  
  756. TWordField::TWordField( void ) : TIntegerField( 0, ftWord )
  757. {
  758. }
  759.  
  760. TWordField::TWordField( PTBDTComponent Owner ) : TIntegerField( Owner, ftWord )
  761. {
  762. }
  763.  
  764. //-----------------------------------------------------------------------------
  765.  
  766. DEFINE_DERIVED_FIELD( TFloatField, TNumericField )
  767.  
  768. TFloatField::TFloatField( void ) : TNumericField( 0, ftFloat)
  769. {
  770. }
  771.  
  772. TFloatField::TFloatField( PTBDTComponent Owner ) : TNumericField( Owner, ftFloat )
  773. {
  774. }
  775.  
  776. TFloatField::TFloatField( PTBDTComponent Owner, TFieldType DataType ) : TNumericField( Owner, DataType )
  777. {
  778. }
  779.  
  780. DEFINE_BDTO_PROP_RW( TFloatField, double, Value );
  781.  
  782. void TFloatField::GetValue( double& v )
  783. {
  784.     GetAsFloat( v );
  785. }
  786.  
  787. void TFloatField::SetValue( double v )
  788. {
  789.     SetAsFloat( v );
  790. }
  791.  
  792. DEFINE_BDTO_PROP_RW( TFloatField, bool, Currency );
  793. DEFINE_BDTO_PROP_RW( TFloatField, double, MaxValue );
  794. DEFINE_BDTO_PROP_RW( TFloatField, double, MinValue );
  795. DEFINE_BDTO_PROP_RW( TFloatField, int, Precision );
  796.  
  797. void TFloatField::GetCurrency( bool& c )
  798. {
  799.     if (field)
  800.         c = MakeBool( field->get_Currency() );
  801. }
  802.  
  803. void TFloatField::SetCurrency( bool c )
  804. {
  805.     if (field)
  806.         field->put_Currency( MakeVariantBool( c ) );
  807. }
  808.  
  809. void TFloatField::GetMaxValue( double& v )
  810. {
  811.     if (field)
  812.         v = field->get_MaxValueAsFloat();
  813. }
  814.  
  815. void TFloatField::SetMaxValue( double v )
  816. {
  817.     if (field)
  818.         field->put_MaxValueAsFloat( v );
  819. }
  820.  
  821. void TFloatField::GetMinValue( double& v )
  822. {
  823.     if (field)
  824.         v = field->get_MinValueAsFloat();
  825. }
  826.  
  827. void TFloatField::SetMinValue( double v )
  828. {
  829.     if (field)
  830.         field->put_MinValueAsFloat( v );
  831. }
  832.  
  833. void TFloatField::GetPrecision( int& p )
  834. {
  835.     if (field)
  836.         p = field->get_Precision();
  837. }
  838.  
  839. void TFloatField::SetPrecision( int p )
  840. {
  841.     if (field)
  842.         field->put_Precision( p );
  843. }
  844.  
  845. //-----------------------------------------------------------------------------
  846.  
  847. DEFINE_DERIVED_FIELD( TCurrencyField, TFloatField )
  848.  
  849. TCurrencyField::TCurrencyField( void ) : TFloatField( 0, ftCurrency )
  850. {
  851. }
  852.  
  853. TCurrencyField::TCurrencyField( PTBDTComponent Owner ) : TFloatField( Owner, ftCurrency )
  854. {
  855. }
  856.  
  857. //-----------------------------------------------------------------------------
  858.  
  859. DEFINE_DERIVED_FIELD( TBCDField, TFloatField )
  860.  
  861. TBCDField::TBCDField( void ) : TFloatField( 0, ftBCD )
  862. {
  863. }
  864.  
  865. TBCDField::TBCDField( PTBDTComponent Owner ) : TFloatField( Owner, ftBCD )
  866. {
  867. }
  868.  
  869. //-----------------------------------------------------------------------------
  870.  
  871. DEFINE_DERIVED_FIELD( TBooleanField, TField )
  872.  
  873. TBooleanField::TBooleanField( void ) : TField( 0, ftBoolean )
  874. {
  875. }
  876.  
  877. TBooleanField::TBooleanField( PTBDTComponent Owner ) : TField( Owner, ftBoolean )
  878. {
  879. }
  880.  
  881. DEFINE_BDTO_PROP_RW( TBooleanField, bool, Value );
  882.  
  883. void TBooleanField::GetValue( bool& v )
  884. {
  885.     GetAsBoolean( v );
  886. }
  887.  
  888. void TBooleanField::SetValue( bool v )
  889. {
  890.     SetAsBoolean( v );
  891. }
  892.  
  893. DEFINE_BDTO_OBJECTPROP_RW( TBooleanField, string, DisplayValues );
  894.  
  895. void TBooleanField::GetDisplayValues( string& s )
  896. {
  897.     if (field)
  898.         AnyString( field->get_DisplayValues() ).GetString( s );
  899. }
  900.  
  901. void TBooleanField::SetDisplayValues( const string& s )
  902. {
  903.     if (field)
  904.         field->put_DisplayValues( AnyString(s).GetPITAnyString() );
  905. }
  906.  
  907. //-----------------------------------------------------------------------------
  908.  
  909. DEFINE_DERIVED_FIELD( TDateTimeField, TField )
  910.  
  911. TDateTimeField::TDateTimeField( void ) : TField( 0, ftDateTime )
  912. {
  913. }
  914.  
  915. TDateTimeField::TDateTimeField( PTBDTComponent Owner ) : TField( Owner, ftDateTime )
  916. {
  917. }
  918.  
  919. TDateTimeField::TDateTimeField( PTBDTComponent Owner, TFieldType DataType ) : TField( Owner, DataType )
  920. {
  921. }
  922.  
  923. DEFINE_BDTO_PROP_RW( TDateTimeField, DATE, Value );
  924.  
  925. void TDateTimeField::GetValue( DATE& v )
  926. {
  927.     GetAsDateTime( v );
  928. }
  929.  
  930. void TDateTimeField::SetValue( DATE v )
  931. {
  932.     SetAsDateTime( v );
  933. }
  934.  
  935. DEFINE_BDTO_OBJECTPROP_RW( TDateTimeField, string, DisplayFormat );
  936.  
  937. void TDateTimeField::GetDisplayFormat( string& s )
  938. {
  939.     if (field)
  940.         AnyString( field->get_DisplayFormat() ).GetString( s );
  941. }
  942.  
  943. void TDateTimeField::SetDisplayFormat( const string& s )
  944. {
  945.     if (field)
  946.         field->put_DisplayFormat( AnyString(s).GetPITAnyString() );
  947. }
  948.  
  949. //-----------------------------------------------------------------------------
  950.  
  951. DEFINE_DERIVED_FIELD( TDateField, TDateTimeField )
  952.  
  953. TDateField::TDateField( void ) : TDateTimeField( 0, ftDate )
  954. {
  955. }
  956.  
  957. TDateField::TDateField( PTBDTComponent Owner ) : TDateTimeField( Owner, ftDate )
  958. {
  959. }
  960.  
  961. //-----------------------------------------------------------------------------
  962.  
  963. DEFINE_DERIVED_FIELD( TTimeField, TDateTimeField )
  964.  
  965. TTimeField::TTimeField( void ) : TDateTimeField( 0, ftTime )
  966. {
  967. }
  968.  
  969. TTimeField::TTimeField( PTBDTComponent Owner ) : TDateTimeField( Owner, ftTime )
  970. {
  971. }
  972.  
  973. //-----------------------------------------------------------------------------
  974.  
  975. DEFINE_DERIVED_FIELD( TBytesField, TField )
  976.  
  977. TBytesField::TBytesField( void ) : TField( 0, ftBytes )
  978. {
  979. }
  980.  
  981. TBytesField::TBytesField( PTBDTComponent Owner ) : TField( Owner, ftBytes )
  982. {
  983. }
  984.  
  985. //-----------------------------------------------------------------------------
  986.  
  987. DEFINE_DERIVED_FIELD( TVarBytesField, TField )
  988.  
  989. TVarBytesField::TVarBytesField( void ) : TField( 0, ftVarBytes )
  990. {
  991. }
  992.  
  993. TVarBytesField::TVarBytesField( PTBDTComponent Owner ) : TField( Owner, ftVarBytes )
  994. {
  995. }
  996.  
  997. //-----------------------------------------------------------------------------
  998.  
  999. DEFINE_DERIVED_FIELD( TBlobField, TField )
  1000.  
  1001. TBlobField::TBlobField( void ) : TField( 0, ftBlob )
  1002. {
  1003. }
  1004.  
  1005. TBlobField::TBlobField( PTBDTComponent Owner ) : TField( Owner, ftBlob )
  1006. {
  1007. }
  1008.  
  1009. TBlobField::TBlobField( PTBDTComponent Owner, TFieldType DataType ) : TField( Owner, DataType )
  1010. {
  1011. }
  1012.  
  1013. void TBlobField::LoadFromFile( const string& filename )
  1014. {
  1015.     if (field)
  1016.         field->LoadFromFile( AnyString(filename).GetPITAnyString() );
  1017. }
  1018.  
  1019. void TBlobField::LoadFromStream( TMemoryStream& stream )
  1020. {
  1021.     if (field)
  1022.         field->LoadFromStream( stream.GetPITMemoryStream() );
  1023. }
  1024.  
  1025. void TBlobField::SaveToFile( const string& filename )
  1026. {
  1027.     if (field)
  1028.         field->SaveToFile( AnyString(filename).GetPITAnyString() );
  1029. }
  1030.  
  1031. void TBlobField::SaveToStream( TMemoryStream& stream )
  1032. {
  1033.     if (field)
  1034.         field->SaveToStream( stream.GetPITMemoryStream() );
  1035. }
  1036.  
  1037. //-----------------------------------------------------------------------------
  1038.  
  1039. DEFINE_DERIVED_FIELD( TMemoField, TBlobField )
  1040.  
  1041. TMemoField::TMemoField( void ) : TBlobField( 0, ftMemo )
  1042. {
  1043. }
  1044.  
  1045. TMemoField::TMemoField( PTBDTComponent Owner ) : TBlobField( Owner, ftMemo )
  1046. {
  1047. }
  1048.  
  1049. DEFINE_BDTO_PROP_RW( TMemoField, bool, Transliterate );
  1050.  
  1051. void TMemoField::GetTransliterate( bool& t )
  1052. {
  1053.     if (field)
  1054.         t = MakeBool( field->get_Transliterate() );
  1055. }
  1056.  
  1057. void TMemoField::SetTransliterate( bool t )
  1058. {
  1059.     if (field)
  1060.         field->put_Transliterate( MakeVariantBool( t ) );
  1061. }
  1062.  
  1063. //-----------------------------------------------------------------------------
  1064.  
  1065. DEFINE_DERIVED_FIELD( TGraphicField, TBlobField )
  1066.  
  1067. TGraphicField::TGraphicField( void ) : TBlobField( 0, ftGraphic )
  1068. {
  1069. }
  1070.  
  1071. TGraphicField::TGraphicField( PTBDTComponent Owner ) : TBlobField( Owner, ftGraphic )
  1072. {
  1073. }
  1074.  
  1075. void TGraphicField::SaveToBitmap( HBITMAP& hbitmap, HPALETTE& hpalette )
  1076. {
  1077.     if (field)
  1078.         field->SaveToBitmap( &hbitmap, &hpalette );
  1079. }
  1080.  
  1081. void TGraphicField::LoadFromBitmap( HBITMAP hbitmap, HPALETTE hpalette )
  1082. {
  1083.     if (field)
  1084.         field->LoadFromBitmap( hbitmap, hpalette );
  1085. }
  1086.  
  1087. //-----------------------------------------------------------------------------
  1088.